<template>
	<view class="content">
		
		<view class="" style="padding: 20upx 40upx;">
			<u-search searchIconSize="0" placeholder="请输入活动名称" label="可修改:" v-model="title" maxlength="18"
				:showAction="false" shape="square" bgColor="#F5F5F5">
			</u-search>
		</view>
		<view class="" style="padding: 20upx 40upx;">
			<u-search searchIconSize="0" placeholder="请输入队伍数量" label="分组组数:" v-model="group_num" :showAction="false"
				@change="change" shape="square" bgColor="#F5F5F5" typeText="number">
			</u-search>
		</view>
		<view class="cooperationType">
			<view :class="cooperationIndex==index?'select cooperationType_item':'cooperationType_item'"
				v-for="(item ,index) in cooperationType" @click="cooperationIndex=index">

				<text>{{item.title}}</text>
				<u-icon name="question-circle-fill" @click="setCooperationTypeShow(index)"></u-icon>
			</view>
		</view>
		<view class="bottom">
			<view class="room" @click="myRoom">
				我的分组
			</view>
			<view class="btn" @click="setSexShow">
				创建分组
			</view>
		</view>
		
		<u-popup :show="sexShow" mode="center" round="12rpx" :safeAreaInsetBottom="false" @close="close">
			<view class="sex">
				<view class="text">
					请选择您的性别
				</view>
				<view class="sex_list">
					<view :class="sex==1?'active':''" style="margin-right: 64upx;" @click="sex=1">
						<u-icon name="man" color="#91BCE6" size="120rpx" :customStyle="{fontWeight:700}"></u-icon>
					</view>
					<view :class="sex==2?'active':''" style="margin-left: 64upx;" @click="sex=2">
						<u-icon name="woman" color="#FFA5D9" size="120rpx" :customStyle="{fontWeight:700}">></u-icon>
					</view>
				</view>
				<view class="join_game" @tap="$u.throttle(establish, 500)">
					加入分组
				</view>
			</view>
		</u-popup>
		
		<u-modal :show="cooperationTypeShow" :title="explain.title" :content='explain.content' confirmText="我知道了"
					confirmColor="#FED194" @confirm="cooperationTypeShow=false"></u-modal>
						<u-toast ref="uToast"></u-toast>
						<Loading />
	</view>

</template>

<script>
	export default {
		data() {
			return {
				sexShow:false,
				sex:1,
				title: '',
				group_num: '',
				cooperationType: [{
					title: '自由分组'
				}, {
					title: '随机分组'
				}],
				cooperationIndex: 1,
				libertyTeam: {},
				restrainTeam: {},
				explain:{},
				cooperationTypeShow:false
			}
		},
		created() {
			this.title = `分组${this.$u.timeFormat(Date.parse(new Date()), 'yyyymmddhhMMss')}`

			this.$myRuquest('home/index/account_det', {
				show_zt: 2
			}).then(res => {
				this.libertyTeam = res.data
			})
			this.$myRuquest('home/index/account_det', {
				show_zt: 3
			}).then(res => {
				this.restrainTeam = res.data
			})
		},
		onShareAppMessage (){},
		methods: {
			setSexShow(){
				if(!this.title) return this.$refs.uToast.show({
						type: 'error',
						message: '分组名必填！'
					})
				if(!this.group_num) return this.$refs.uToast.show({
						type: 'error',
						message: '队伍数量必填！'
					})
				this.sexShow=true
			},
			myRoom() {
				uni.navigateTo({
					url: './teamFastList'
				})
			},
			close(){
				this.sexShow=false
			},
			change(value) {
				if (~~value > 100) {
					this.group_num = 100
					this.$refs.uToast.show({
						type: 'error',
						message: '队伍数量最多100！'
					})
				}
			},
			setCooperationTypeShow(index) {
				this.explain = index ? this.restrainTeam : this.libertyTeam
				this.cooperationTypeShow = true
			},
			establish() {
				let data = {
					title: this.title,
					group_num: this.group_num,
					team_type: this.cooperationIndex + 1,
					sex:this.sex
				}
				this.$myRuquest('home/group/group_add', data).then(res => {
					uni.navigateTo({
						url:'./teamFast?gameId='+res.data.game_id
					})

				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #FFFFFF;
		padding-bottom: 160upx;
		min-height: calc(100vh - 180rpx);
	}
	.cooperationType {
		display: flex;
		justify-content: space-around;
		padding: 0upx 40upx;

		.cooperationType_item {
			display: flex;
		}

		.cooperationType_item>text {
			padding: 10upx 40upx;
			background-color: #fff;
			border-radius: 30upx;
			font-size: 28upx;
			transition: all .5s;
			margin-right: 10upx;
		}
	}

	.select_,
	.select>text {
		background-color: #FED194 !important;
		color: #AC7D3D;
	}


	.bottom {
		padding: 24upx 20upx;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 9999;
		width: calc(100vw - 40upx);
		display: flex;
		align-items: center;

		.room {
			width: 200upx;
			margin-right: 20upx;
			text-align: center;
			background: #dcdcdc;
			color: #999;
			height: 80upx;
			line-height: 80upx;
			border-radius: 8rpx;
		}

		.btn {
			flex: 1;
			height: 80upx;
			margin: 0 auto;
			background-color: #FED194;
			color: #AC7D3D;
			// border-radius: 50upx;
			font-size: 36upx;
			line-height: 80upx;
			text-align: center;
			border-radius: 8rpx;
		}
	}
	.sex {
		padding: 0 132upx;
	
		.text {
			font-size: 36upx;
			color: #333333;
			font-weight: 700;
			text-align: center;
			padding: 40upx 0;
		}
	
		.sex_list {
			display: flex;
			justify-content: space-between;
	
			view {
				width: 140upx;
				height: 140upx;
				padding-top: 10rpx;
				background-color: #E8E8E8;
				border-radius: 8upx;
			}
	
			.active {
				border: 2upx solid #91BCE6;
			}
		}
	
		.join_game {
			width: 234upx;
			height: 64upx;
			line-height: 64upx;
			text-align: center;
			border-radius: 64upx;
			margin: 0 auto;
			margin-top: 56upx;
			margin-bottom: 20upx;
			font-size: 28upx;
			color: #AC7D3D;
			background-color: #FED194;
		}
	}
</style>
